Ext.namespace("Microtraining.Admin");
Mt = Microtraining.Admin;
/**
 * 全局配置
 */
Mt.Config={
    /**
     * 访问历史记录的组件标识分割符
     */
    TokenDelimiter:':',
    /**
     * 操作者
     */
    Operator:'',
    /**
     * 在线编辑器类型。
     * 1:CkEditor,2:KindEditor,3:xhEditor,4:UEditor
     * 配合Action的变量配置$online_editor
     */
    OnlineEditor:4, 
    /**
     * 提供第三方公用使用的窗口，一个应用只有一个这样的窗口
     */
    ViewOnlyWindow:null,
    ViewOnlyWindows:{},
    /**
     * 初始化
     */
    Init:function(){
        if (Ext.util.Cookies.get('OnlineEditor')!=null){
            Mt.Config.OnlineEditor=Ext.util.Cookies.get('OnlineEditor');
        }
        if (Ext.util.Cookies.get('operator')!=null){

            var operator = Ext.util.Cookies.get('operator') ;
            var rolename = Ext.decode(Ext.util.Cookies.get('rolename')) ;

            Mt.Config.Operator = operator + ' (' + rolename + ')';
        }
        if (Ext.util.Cookies.get('admin_id')!=null){
            Mt.Config.Admin_id=Ext.util.Cookies.get('admin_id');
        }
    }
};

Ext.onReady(function(){
    Ext.QuickTips.init();
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
    Mt.Viewport = new Ext.Viewport({
        layout: 'border',
        items: [
          Mt.Layout.HeaderPanel,Mt.Layout.LeftPanel,Mt.Layout.CenterPanel
        ]
    });
    Mt.Config.Init();
    Mt.Layout.Init();
    Mt.Viewport.doLayout();
    setTimeout(function(){
        Ext.get('loading').remove();
        Ext.get('loading-mask').fadeOut({remove:true});
    }, 250);

    //让浏览器的后退前进跟从Tab访问的历史记录
    Ext.History.init();

    // Handle this change event in order to restore the UI to the appropriate history state
    Ext.History.on('change', function(token){
        if(token){
            var parts = token.split(Mt.Config.TokenDelimiter);
            var tabPanel = Ext.getCmp(parts[0]);
            var tabId = parts[1];
            tabPanel.show();
            tabPanel.setActiveTab(tabId);
        }
    });
});